package com.tanhua.server.controller;


import com.tanhua.model.vo.QuestionnaireVo;
import com.tanhua.model.vo.ReportVo;
import com.tanhua.server.service.SoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class SoulController {

    @Autowired
    private SoulService soulService;

    /**
     * 测灵魂-问卷列表
     *
     * @return
     */
    @GetMapping
    public ResponseEntity questionnaire() {
        List<QuestionnaireVo> questionnaireVoList = soulService.questionnaire();
        return ResponseEntity.ok(questionnaireVoList);
    }

    /**
     * 测灵魂-提交问卷
     *
     * @return
     */
    @PostMapping
    public ResponseEntity putQuestionnaire(@RequestBody Map map) {
        ArrayList<Map<String, String>> list = (ArrayList<Map<String, String>>) map.get("answers");
        String reportId = soulService.putQuestionnaire(list);
        return ResponseEntity.ok(reportId);
    }

    /**
     * 测灵魂-查看结果
     *
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity questionnaireResult(@PathVariable Long id) {
        ReportVo reportVo = soulService.questionnaireResult(id);
        return ResponseEntity.ok(reportVo);
    }
}
